package com.emm.yixun.estate.service.impl.app.manage;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.emm.yixun.basic.service.ProjectBuildingService;
import com.emm.yixun.common.app.GetBuildingListReqDto;
import com.emm.yixun.common.app.GetBuildingListResDto;
import com.emm.yixun.common.app.servletentity.BuildingListRes;
import com.emm.yixun.common.enums.ResultEnum;
import com.emm.yixun.common.model.ProjectBuilding;
import com.emm.yixun.common.model.dto.ProjectBuildingDto;

@Service("getBuildingListManage")
public class GetBuildingListManage {

	@Autowired
	private ProjectBuildingService projectBuildingService;
	
	/**
	 * 查询可关注房源-楼栋
	 * @param reqDto
	 * @return
	 */
	public GetBuildingListResDto getBuildingList(GetBuildingListReqDto reqDto) {
		GetBuildingListResDto resDto = new GetBuildingListResDto();
		try{
			ProjectBuildingDto pbDto = new ProjectBuildingDto();
			pbDto.setMerchantId(reqDto.getMerchantId());
			pbDto.setProjectCode(reqDto.getProjectCode());
			if(reqDto.getPremisesId() !=null && !"".equals(reqDto.getPremisesId())){
				pbDto.setPremisesId(Long.parseLong(reqDto.getPremisesId()));
			}
			List<ProjectBuilding> pbList = projectBuildingService.selectListByDto(pbDto);
			List<BuildingListRes> buildingList = new ArrayList<BuildingListRes>();
			if(pbList.size() > 0){
				for(ProjectBuilding pb: pbList){
					BuildingListRes blRes = new BuildingListRes();
					blRes.setBuildingId(String.valueOf(pb.getId()));
					blRes.setBuildingName(pb.getBuildingName());
					buildingList.add(blRes);
				}
				resDto.setBuildingList(buildingList);
			}else{
				resDto.setBuildingList(null);
			}
			resDto.setResult(ResultEnum.SUCCESS.getNo());
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("00000");
			resDto.setErrorMsg("可关注楼栋查询失败!");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		return resDto;
	}
	
}
